/**
 * Created by liujie on 2017/10/4.
 */
(function ($,window,undefined) {
    var $menuBox = $("ul#menu-box"),
        hrefs = {
            "home":"/mainFrame",
            "dataManage":"/dataManage",
            "monitor":"/monitor",
            "application":"/applicationManage",
            "reportManage":"/reportManage",
            "systemManage":"/moreDataSetting"
        };
    $menuBox.on("click","li",function (e) {
        var $this = $(this);
        if($this.hasClass("active")){
            return false
        }
        var _href_key =$this.attr("data-href");
        if(_href_key == "dataManage"){
            hrefs["dataManage"] = matchSecondUrl("4");
        }
        if(_href_key == "application"){
            hrefs["application"] = matchSecondUrl("7");
        }
        $.link(hrefs[_href_key]);
        try{
            if(refZtreeInterval){
                clearInterval(refZtreeInterval);
            }
            if(setTimePost){
                clearTimeout(setTimePost);
            }
            if(setTimeQueryTreeData){
                clearTimeout(setTimeQueryTreeData);
            }
            if(setIntListCount){
                clearInterval(setIntListCount);
            }
            if(setIntRefDept){
                clearInterval(setIntRefDept);
            }
        }catch (e){

        }
    });
    $("#loginOut").click(function () {
        $.messageExt.confirm("退出登录","确认退出登录？",function (r) {
            if(r){
                $.link("/logout");
            }
        });
    });

    $(window).resize(function() {
        if(document.getElementById("myMapParent"))
        {
            $("#myMapParent").css({"height":$(window).height()-48-20 + "px"});
        }
        if(document.getElementById("bottom-box"))
        {
            $("#bottom-box").css({"width":$(window).width()-240 + "px"});
        }

    });
})(jQuery,window,undefined);

function matchSecondUrl(key){
    var secondMenus = window.sessionStorage.getItem("chidlMenus");
    if(secondMenus){
        secondMenus = JSON.parse(secondMenus);
        var menuControllerNames = [];
        if(secondMenus.length){
            for(var k=0;k<secondMenus.length;k++){
                var parentId = secondMenus[k]["parentId"];
                var item = secondMenus[k]["controllerName"];
                if(parentId == key){
                    menuControllerNames.push(item)
                }
            }
        }
        if(key=="4"){
            var resultControllerNames = ["/dataManage","/accountManage","/deviceManage","/roleManage"];
            for(var m=0;m<resultControllerNames.length;m++){
                var itemVal = resultControllerNames[m];
                for(var j=0,
                        _len=menuControllerNames.length;j<_len;j++){
                    var url_val = menuControllerNames[j];
                    if(itemVal == url_val){
                        return itemVal
                    }
                }
            }
        }
        if(key=="7"){
            var applicationControllerNames = ["/applicationManage","/electronManage"];
            for(var n=0;n<applicationControllerNames.length;n++){
                var itemVal = applicationControllerNames[n];
                for(var j=0,
                        _len=menuControllerNames.length;j<_len;j++){
                    var url_val = menuControllerNames[j];
                    if(itemVal == url_val){
                        return itemVal
                    }
                }
            }
        }

    }
}
